﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Security.Claims;
using XJay.Scheduler.Model;

namespace XJay.Scheduler.Controllers
{
    /// <summary>
    /// 基础控制器
    /// </summary>
    [ApiController]
    [Authorize]
    public class BaseController : ControllerBase
    {
        public BaseController()
        {
            var _httpContextAccessor = IocManager.Instance.GetService<IHttpContextAccessor>();
            UserInfo.UserName = _httpContextAccessor.HttpContext?.User.FindFirstValue("UserName");
            UserInfo.UID =int.Parse(_httpContextAccessor.HttpContext?.User.FindFirstValue("UID") ?? "0");
            UserInfo.Role = int.Parse(_httpContextAccessor.HttpContext?.User.FindFirstValue("Role") ?? "0");
        }
        public UserInfoAccessor UserInfo { get; private set; } = new UserInfoAccessor();
    }
}
